
package com.zhan.utils;


import cn.hutool.core.text.StrSpliter;
import com.google.common.collect.Lists;

import java.util.Collection;
import java.util.List;

/**
 * @author 白尚兵
 * @date 2019/9/4 15:51
 **/
public class MyStringUtils {
    public static String concat(Collection<String> collection) {
        return concat(collection, "");
    }

    public static String concat(Collection<String> collection, String separator) {
        StringBuilder sb = new StringBuilder();
        if (collection != null) {
            for (String s : collection) {
                sb.append(s).append(separator);
            }
        }
        return sb.toString();
    }

    public static String concat(String separator, String... strs) {
        if (separator == null) {
            separator = "";
        }
        StringBuilder sb = new StringBuilder();
        for (String str : strs) {
            sb.append(str).append(separator);
        }
        int len = sb.length();
        return sb.substring(0, len - separator.length());
    }

    public static String concat(String... strs) {
        return concat(null, strs);
    }

    public static String convertEmptyAndUnknown(String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        ;
        if ("unknown".equalsIgnoreCase(value)) {
            return null;
        }
        return value;
    }

    public static List<Long> splitLongData(String str, String separator) {
        String[] strDatas = StrSpliter.splitToArray(str, separator, 0, true, true);
        List<Long> longDatas = Lists.newArrayList();
        for (String strData : strDatas) {
            longDatas.add(Long.valueOf(strData));
        }
        return longDatas;
    }

    public static List<Long> splitLongData(String str) {
        return splitLongData(str, ",");
    }

    public static String likeStr(String value) {
        return "%" + value + "%";
    }
}
